﻿CREATE TABLE [dbo].[Data]
(
	[DataId] BIGINT NOT NULL PRIMARY KEY IDENTITY, 
    [ParentDataId] BIGINT NULL, 
	[ParentId] AS [ParentDataId],
	[ProjectId] int NOT NULL,
	[DataCategoryId] SMALLINT NOT NULL, 
    [DataName] NVARCHAR(50) NOT NULL, 
    [DataDefinition] NVARCHAR(MAX) NULL, 
    [DataType] NVARCHAR(50) NULL, 
    [DataFullPath] NVARCHAR(MAX) NULL, 
	[DataFullName] AS CASE WHEN [DataFullPath] IS NULL THEN [DataName] ELSE [DataFullPath] + '.' + [DataName] END,
    CONSTRAINT [FK_Data_Data] FOREIGN KEY ([ParentDataId]) REFERENCES [dbo].[Data]([DataId]), 
    CONSTRAINT [FK_Data_Project] FOREIGN KEY ([ProjectId]) REFERENCES [dbo].[Project]([ProjectId]), 
    CONSTRAINT [FK_Data_DataCategory] FOREIGN KEY ([DataCategoryId]) REFERENCES [dbo].[DataCategory]([DataCategoryId])
)
